<?php
/**
 * Created by JetBrains PhpStorm.
 * User: zhouyang
 * Date: 13-7-15
 * Time: 下午4:31
 * To change this template use File | Settings | File Templates.
 */
class CateHasUsersDB  extends DBReader{

    //添加 cate 拥有的 user 信息
    public function addCateHasUsers($cate_id,$user_id){

        $sql = "insert into cate_has_users(cate_id,user_id) values(:cate_id,:user_id)";

        $bindarr = array(
            'cate_id'=>$cate_id,
            'user_id'=>$user_id,
        );
        $this->db()->execute($sql,$bindarr);
        return $this->db()->lastInsertId();
    }

    //删除 cate_id 对应的信息
    public function delByCateId($cate_id){
        $bindarr = array(
            'cate_id'=>$cate_id,
        );

        $sql = "delete from cate_has_users where cate_id = :cate_id";
        $this->db()->execute($sql,$bindarr);
    }

    //删除 user_id 对应的信息
    public function delByUserId($user_id){
        $bindarr = array(
            'user_id'=>$user_id,
        );

        $sql = "delete from cate_has_users where user_id = :user_id";
        $this->db()->execute($sql,$bindarr);
    }

    //获取用户所有的权限分类ID
    public function getCateIdsByUserId($user_id)
    {
        $sql = "select cate_id from cate_has_users where user_id = :user_id";

        $ucate_ids = $this->db()->getOneAll($sql, array('user_id' => $user_id));

        return $ucate_ids;
    }

}